package com.wx.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wx.pojo.QRCode;
import com.wx.service.QRCodeService;
/**
 * 二维码
 *
 */
@Controller
@RequestMapping("/qrCode")
public class QRCodeController {

	@Autowired
	private QRCodeService qRCodeService;
	
	/**
	 * 查询二维码
	 * @param userId
	 * @return
	 */
	@RequestMapping(value="/findQrCode",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> findQrCode(@RequestParam("user_id")String userId) {
		Map<String,Object> modelMap=new HashMap<String,Object>();
		System.out.println(userId);
		if(userId==null || userId=="") {
			modelMap.put("errno", 1);//判断为空
			return modelMap;
		}
		QRCode qrCode=qRCodeService.findQRCodeByUserId(userId);
		if(qrCode==null) {
			modelMap.put("errno", 2);//未查询到该用户的二维码
			return modelMap;
		}
		modelMap.put("errno", 0);
		modelMap.put("qrUrl", qrCode.getQrUrl());
		return modelMap;
	}
	
}
